#include<cstdio>
#include<cstring>
int bad[155][13];
int m,n,k;
int fac[13];
int dp[2][60000];
int infA[13],infB[13];
void init()
{
	fac[0]=1;
	for(int i=1;i<=10;i++)
		fac[i]=fac[i-1]*3;
}
int hash(int a[])
{
	int ans=0;
	for(int i=0;i<11;i++)
		ans+=fac[i]*a[i];
	return ans;
}
void code(int s,int *a)
{
	for(int i=0;i<m;i++)
	{
		a[i]=s%3;
		s/=3;
	}
}
int max(int x,int y)
{
	return x>y?x:y;
}
void dfs(int x,int y,int cnt,int state)
{
	int nows;
	dp[x%2][state]=max(dp[x%2][state],dp[(x+1)%2][hash(infA)]);
	if(y>=m-1)return ;
	if(y<m-1&&infA[y]==0&&infA[y+1]==0&&infB[y]==0&&infB[y+1]==0)
	{
		infB[y]=infB[y+1]=2;
		nows=hash(infB);
		dp[x%2][nows]=max(dp[x%2][nows],cnt+1);
		dfs(x,y+2,cnt+1,nows);
		infB[y]=infB[y+1]=0;
	}
	if(y<m-2&&infB[y]==0&&infB[y+1]==0&&infB[y+2]==0)
	{
		infB[y]=infB[y+1]=infB[y+2]=2;
		nows=hash(infB);
		dp[x%2][nows]=max(dp[x%2][nows],cnt+1);

		dfs(x,y+3,cnt+1,nows);
		infB[y]=infB[y+1]=infB[y+2]=0;
	}
	dfs(x,y+1,cnt,state);
}

int main()
{
	freopen("test.in","r",stdin);
	int t,i,j;
	scanf("%d",&t);
	init();
	while(t--)
	{
		scanf("%d%d%d",&n,&m,&k);
		memset(bad,0,sizeof(bad));
		for(i=0;i<k;i++)
		{
			int x,y;
			scanf("%d%d",&x,&y);
			bad[x-1][y-1]=1;
		}
		if(n<2)
		{
			printf("0\n");
			continue;
		}
		memset(dp[1],-1,sizeof(dp[1]));
		memset(infA,0,sizeof(infA));
		
		for(i=0;i<m;i++)
			infA[i]=bad[0][i]+1;
		
		int state = hash(infA);
		dp[1][state]=0;

		for(i=2;i<=n;i++)
		{
			memset(dp[i%2],-1,sizeof(dp[i%2]));
			memset(infB,0,sizeof(infB));

			for(j=0;j<fac[m];j++)
			{
				if(dp[(i+1)%2][j]==-1)continue;
				code(j,infA);
				for(int L=0;L<m;L++)
				{
					if(bad[i-1][L]==1)infB[L]=2;
					else infB[L]=infA[L]-1;
					if(infB[L]<0)infB[L]=0;
				}
				dfs(i,0,dp[(i+1)%2][j],hash(infB));
			}
		}
		int ans=0;
		for(j=0;j<fac[m];j++)
		{
			if(dp[0][j]>ans)ans=dp[0][j];
			if(dp[1][j]>ans)ans=dp[1][j];
		}
		printf("%d\n",ans);
	}
	return 0;
}

